package com.appleframework.module.usermgr.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.appleframework.core.BaseService;
import com.appleframework.core.Page;
import com.appleframework.core.ServiceException;
import com.appleframework.module.usermgr.dao.ItemMgrDao;
import com.appleframework.module.usermgr.vo.Item;

@Service("itemMgrService")
public class ItemMgrService extends BaseService {

	@Autowired
	private ItemMgrDao itemMgrDao;

	/**
	 * 查询所有记录
	 * @return
	 * @throws ServiceException
	 */
	public List<Item> getItems() throws ServiceException {

		try {
			return itemMgrDao.getItems();
		} catch (Exception e) {
			throw new ServiceException("异常", e);
		}

	}

	/**
	 * 分页查询-根据name/所有，进行分页显示
	 * @param start 记录开始
	 * @param pageSize 每页显示的记录数
	 * @param name 名称
	 * @return
	 * @throws ServiceException
	 */
	
	public List<Item> getPage(Integer start, Integer pageSize,String name)
			throws ServiceException {

		try {
			return itemMgrDao.getPage(start, pageSize,name);
		} catch (Exception e) {
			throw new ServiceException("异常", e);
		}

	}
	
	/**
	 * 根据id查询
	 * @param id
	 * @return
	 */
	public Item getById(Integer id){
		return itemMgrDao.getItemsByColunm("id", id).get(0);
		
	}
	
	

	/**
	 * 添加
	 * @param item
	 * @throws ServiceException
	 */
	public void addItem(Item item) throws ServiceException {

		itemMgrDao.addItem(item);

	}

	/**
	 * 根据id删除
	 * @param id
	 */
	public void deleteItemById(Integer id) {

		itemMgrDao.deleteItem("id", id);

	}

	/**
	 * 更新
	 * @param item
	 */
	public void updateItem(Item item) {

		itemMgrDao.updateItem(item);

	}
	
	/**
	 * 查询一共多少条记录  
	 * 
	 * @return 总共多少条记录
	 */
	public int findRecordCount(){
		return itemMgrDao.findRecordCount();
	};

}
